package org.sais.rasoid;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

public class CardViewActivity extends FragmentActivity {
	
	private int mOffset;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pager);
		mOffset = getIntent().getIntExtra("offset", 0);
		final int size = Tools.getIndices().size();
		
		PagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {

			@Override
			public int getCount() {
				return size;
			}

			@Override
			public Fragment getItem(int position) {
				return new CardViewFragment(position);
			}
		};

		// wrap pager to provide infinite paging with wrap-around
		PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter);
		
		// actually an InfiniteViewPager
		ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
		viewPager.setAdapter(wrappedAdapter);
		viewPager.setCurrentItem(mOffset);
	}
}
